import {onMounted, ref} from "vue";

/**
 * 自定义分页钩子
 * @param initData
 */
export function usePagination(initData: () => void) {
    const pageSize = ref(5)
    const counts = ref(0)
    const page = ref(1)
    const tableLoading = ref(false)

    const handleSizeChange = (val: number) => {
        page.value = 1
        pageSize.value = val
        initData()
    }
    const handleCurrentChange = (val: number) => {
        page.value = val
        initData()
    }

    onMounted(async ()=>{
        initData()
    })
    return {
        page,
        pageSize,
        counts,
        tableLoading,
        handleCurrentChange,
        handleSizeChange
    }

}
